import {
    createCodeGenerateService,
    deleteCodeGenerateService,
    downloadCodeService,
    generagePermissions,
    getCodeGenerateListService,
    getCodeGenerateService,
    updateCodeGenerateService,
    viewCodeService,
} from "@/services/admin/codeGenerate";
import express from "express";

const router = express.Router();

router.get("/viewCode", (req, res) => {
    /*
        #swagger.tags = ['管理端代码生成']
        #swagger.path = '/admin-api/codeGenerate/viewCode'
        #swagger.description = '查看生成的代码'
        #swagger.parameters['_id'] = { in: 'query', description: '代码生成ID', type: 'string', required: true }
    */
    viewCodeService(req, res);
});

router.get("/downloadCode", (req, res) => {
    /*
        #swagger.tags = ['管理端代码生成']
        #swagger.path = '/admin-api/codeGenerate/downloadCode'
        #swagger.description = '下载生成的代码'
        #swagger.parameters['_id'] = { in: 'query', description: '代码生成ID', type: 'string', required: true }
    */
    downloadCodeService(req, res);
});

router.get("/", (req, res) => {
    /*
        #swagger.tags = ['管理端代码生成']
        #swagger.path = '/admin-api/codeGenerate'
        #swagger.description = '获取代码生成列表'
        #swagger.parameters['page'] = { in: 'query', description: '页号', type: 'integer' }
        #swagger.parameters['pageSize'] = { in: 'query', description: '每页个数', type: 'integer' }
        #swagger.parameters['modelName'] = { in: 'query', description: '模型名称', type: 'string' }
        #swagger.parameters['collectionName'] = { in: 'query', description: '集合名称', type: 'string' }
    */
    getCodeGenerateListService(req, res);
});

router.get("/:_id", (req, res) => {
    /*
        #swagger.tags = ['管理端代码生成']
        #swagger.path = '/admin-api/codeGenerate/{_id}'
        #swagger.description = '获取指定代码生成'
        #swagger.parameters['_id'] = { in: 'path', description: '代码生成ID', type: 'string', required: true }
    */
    getCodeGenerateService(req, res);
});

router.post("/", (req, res) => {
    /*
        #swagger.tags = ['管理端代码生成']
        #swagger.path = '/admin-api/codeGenerate'
        #swagger.description = '创建代码生成'
        #swagger.requestBody = {
            required: true,
            content: {
                "application/json": {
                    schema: {
                        type: "object",
                        required: ['modelName', 'fields', 'operations', 'resultTypes'],
                        properties: {
                            modelName: { description: '模型名称', type: 'string' },
                            pageName: { description: '页面名称', type: 'string' },
                            collectionName: { description: '集合名称', type: 'string' },
                            desc: { description: '描述', type: 'string' },
                            fields: { description: '字段列表', type: 'array', items: { type: 'string' } },
                            operations: { description: '操作列表', type: 'array', items: { type: 'string' } },
                            resultTypes: { description: '结果类型', type: 'array', items: { type: 'string' } },
                            parentFind: { description: '父查找配置', type: 'object' },
                            lookupList: { description: '关联查询配置', type: 'array', items: { type: 'object' } },
                            permissionKey: { description: '权限键', type: 'string' }
                        }
                    }
                }
            }
        }
    */
    createCodeGenerateService(req, res);
});

router.put("/", (req, res) => {
    /*
        #swagger.tags = ['管理端代码生成']
        #swagger.path = '/admin-api/codeGenerate'
        #swagger.description = '更新代码生成'
        #swagger.requestBody = {
            required: true,
            content: {
                "application/json": {
                    schema: {
                        type: "object",
                        required: ['_id'],
                        properties: {
                            _id: { description: '代码生成ID', type: 'string' },
                            modelName: { description: '模型名称', type: 'string' },
                            pageName: { description: '页面名称', type: 'string' },
                            collectionName: { description: '集合名称', type: 'string' },
                            desc: { description: '描述', type: 'string' },
                            fields: { description: '字段列表', type: 'array', items: { type: 'string' } },
                            operations: { description: '操作列表', type: 'array', items: { type: 'string' } },
                            resultTypes: { description: '结果类型', type: 'array', items: { type: 'string' } },
                            parentFind: { description: '父查找配置', type: 'object' },
                            lookupList: { description: '关联查询配置', type: 'array', items: { type: 'object' } },
                            permissionKey: { description: '权限键', type: 'string' }
                        }
                    }
                }
            }
        }
    */
    updateCodeGenerateService(req, res);
});

router.delete("/", (req, res) => {
    /*
        #swagger.tags = ['管理端代码生成']
        #swagger.path = '/admin-api/codeGenerate'
        #swagger.description = '删除代码生成'
        #swagger.requestBody = {
            required: true,
            content: {
                "application/json": {
                    schema: {
                        type: "object",
                        required: ['_id'],
                        properties: {
                            _id: { description: '代码生成ID', type: 'string' }
                        }
                    }
                }
            }
        }
    */
    deleteCodeGenerateService(req, res);
});

router.post('/generagePermissions', (req, res)=>{
    /*
        #swagger.tags = ['管理端代码生成']
        #swagger.path = '/admin-api/code-generate/generagePermissions'
        #swagger.description = '生成CRUD权限配置'
        #swagger.requestBody = {
            required: true,
            content: {
                "application/json": {
                    schema: {
                        type: "object",
                        required: ['_id'],
                        properties: {
                            _id: { description: '代码生成ID', type: 'string' },
                        }
                    }
                }
            }
        }
    */
   generagePermissions(req, res);
})

export default router;
